﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Manager.Common;
using Manager.App_Code;
using System.Linq;

namespace Manager.FormAdd_Edit
{
    public partial class frm_TienThanhToan : DevExpress.XtraEditors.XtraForm
    {
        NewPearl_HotelDataContext db = new NewPearl_HotelDataContext();
        public double tienThanhToanVND = 0;
        public double tienThanhToanUSD = 0;
        TienTe tienTe = null;
        double tongTienVND = 0;
        public bool isClose = false;

        public frm_TienThanhToan(string tongTienThanhToan, string MaTienTe)
        {
            InitializeComponent();
            tienTe = db.TienTes.SingleOrDefault(t => t.MaDonVi == MaTienTe);
            tongTienVND = CommonFunction.ParseDouble(tongTienThanhToan) * tienTe.TyGiaThamKhao.Value;
            lblTongTien.Text = tongTienThanhToan + " " + MaTienTe;
            lblTongTien.Refresh();
        }

        private void btnCheckOut_Click(object sender, EventArgs e)
        {
            tienThanhToanVND = CommonFunction.ParseDouble(txtTienVND.Text);
            tienThanhToanUSD = CommonFunction.ParseDouble(txtTienUSD.Text);
            var tongTien = tienThanhToanUSD * tienTe.TyGiaThamKhao.Value + tienThanhToanVND;
            if (tongTienVND != tongTien)
            {
                DialogResult dr = MessageBox.Show("Tổng tiền trả không khớp với tiền phải thanh toán.\nBạn có muốn tiếp tục ?", "Thông báo", MessageBoxButtons.YesNo);
                if (dr == DialogResult.Yes)
                    this.Close();
                else
                {
                    txtTienVND.Text = "0";
                    txtTienUSD.Text = "0";
                }
            }
            else
                this.Close();
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            isClose = true;
            this.Close();
        }
    }
}